package controller;

import java.util.List;

import com.jfinal.core.Controller;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import model.Site;
import model.Weather;
import server.MyServerHandler;
/**
 * 获取数据库大气数据信息
 */
public class WeatherController extends Controller {
	
	
//	@CacheName("bbsRedis")
	public void index() {
		Integer sites = getParaToInt("sites",1);
		List<Weather> weather = Weather.dao.find("select * from weather where SiteID=?",sites);
		List<Site> site = Site.dao.find("select* from site");
		setAttr("weather",weather);
		setAttr("site",site);
		render("data.jsp");
	}
	//实现数据获取
//	@CacheName("bbsRedis")
	public void GetData(){
		if(MyServerHandler.Get()!=null)
			MyServerHandler.Get().writeAndFlush(Unpooled.copiedBuffer("Select All data!",CharsetUtil.UTF_8));
		index();
	}
	//实现数据刷新
//	@CacheName("bbsRedis")
	public void Refresh(){
		index();
	}
	public void Datas(){
		List<Weather> weather = Weather.dao.find("select * from weather");
		setAttr("weather",weather);
		render("datas.jsp");
	}
	
}
